import { createRouter,createWebHashHistory, createWebHistory } from 'vue-router';
import Layout from '@/layout/index.vue';
import NotFound from '@/view/404.vue';
import Login from '@/view/login.vue';
import { isExternal } from '@/utils/validate';

export const constantRoutes = [
    { 
        path: '/', 
        name: 'Home',
        component: Layout,
        redirect: to => {
            return { path: '/index'}
        },
        children: [
            { 
                path: 'index',
                name: 'Index',
                component: () => import('@/view/home/index.vue'),
                meta: { icon: 'HomeFilled', noCache: false, title: '首页', affix: true  }
            }
        ]
    },
    { 
        path: '/mapManagement', 
        name: 'MapManagement',
        component: Layout,
        meta: { icon: 'MapLocation', noCache: false, title: '地图管理'  },
        children: [
            { 
                path: 'mapList',
                name: 'MapList',
                component: () => import('@/view/mapManagement/mapList.vue'),
                meta: { icon: 'List', noCache: false, title: '地图列表'  }
            },
            { 
                path: 'mapIconList',
                name: 'MapIconList',
                component: () => import('@/view/mapManagement/mapIconList.vue'),
                meta: { icon: 'List', noCache: false, title: '图标列表'  }
            }
        ]
    },
    { 
        path: '/buildingManagement', 
        name: 'BuildingManagement',
        component: Layout,
        children: [
            { 
                path: 'buildingList',
                name: 'BuildingList',
                component: () => import('@/view/buildingManagement/index.vue'),
                meta: { icon: 'OfficeBuilding', noCache: false, title: '建筑列表'  }
            }
        ]
    },
    { 
        path: '/document', 
        name: 'Document',
        component: Layout,
        children: [
            { 
                path: 'operatingInstructions',
                name: 'OperatingInstructions',
                component: () => import('@/view/document/index.vue'),
                meta: { icon: 'House', noCache: false, title: '操作说明'  }
            }
        ]
    },
    { 
        path: '/editor',
        name: 'Editor',
        component: () => import('@/view/mapEditor/index.vue'),
        meta: { hidden: true, title: '地图编辑器' }
    },
    {
        path: '/mapPreview/:id',
        name: 'MapPreview',
        component: () => import('@/view/mapEditor/preview.vue'),
        meta: { hidden: true, title: '地图预览' }
    },
    {
        path: '/mapMobile/:placeFloorId/:robotCode',
        name: 'MapMobile',
        component: () => import('@/view/mapEditor/mapMobile.vue'),
        meta: { hidden: true, title: '地图预览' }
    },
    { 
        path: '/login', 
        name: 'Login',
        component: Login,
        meta: { hidden: true, title: '登录' }
    },
    { 
        path: '/:pathMatch(.*)*', 
        name: 'NotFound',
        component: NotFound,
        meta: { hidden: true, title: '404' }
    },

]

const router = createRouter({
    history: createWebHashHistory(),
    routes: constantRoutes
})

export default router